package com.ayoka.adapter;

import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.ayoka.R;
import com.ayoka.bean.CourseAssignmentBean.QuestionBean;
import com.ayoka.bean.CourseAssignmentBean.OptionBean;
import com.jcp.baselibrary.brvah.BaseQuickAdapter;
import com.jcp.baselibrary.brvah.BaseViewHolder;
import com.jcp.baselibrary.brvah.layoutmanager.FlowLayoutManager;

import java.util.List;

/**
 * Created by jinchunping on 2018/4/11.
 */

public class CourseAssignmentInputOptionAdapter extends BaseQuickAdapter<QuestionBean, BaseViewHolder> {

    private String inputContent;


    public CourseAssignmentInputOptionAdapter() {
        super(R.layout.item_course_assignment_input_option, null);
    }

    @Override
    protected void convert(final BaseViewHolder holder, final QuestionBean item) {
        final EditText edtContent = holder.getView(R.id.edt_content);
        edtContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                inputContent = s.toString().trim();
            }
        });
        RecyclerView recyclerView = holder.getView(R.id.recyclerView);
        recyclerView.setLayoutManager(new FlowLayoutManager());
        BaseQuickAdapter adapter = new BaseQuickAdapter<OptionBean, BaseViewHolder>(R.layout.item_course_assignment_input_choice_option, item.Options) {
            @Override
            protected void convert(BaseViewHolder holder, OptionBean item) {
                holder.setText(R.id.tv_name, item.Option);
            }

        };
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                edtContent.append((String) adapter.getItem(position));
            }
        });
        recyclerView.setAdapter(adapter);
    }

    public String getInputContent() {
        return inputContent;
    }
}
